var orderDate = window.localStorage.getItem("orderDate");
var timeSpan = window.localStorage.getItem("timeSpan");
if (orderDate != null) {
  $("#orderDate")[0].value = orderDate;
}
if (timeSpan != null) {
  $("#timeSpan")[0].value = timeSpan;
}

$("#ordering").click(function(){
   var orderDate_ = $("#orderDate")[0].value;
   var timeSpan_ = $("#timeSpan")[0].value;
   window.localStorage.setItem("orderDate", orderDate_);
   window.localStorage.setItem("timeSpan", timeSpan_);
   if (timeSpan_ == "-1") {
     var tryTimeSpans = ["811","1215","1518","1820"];
     for (var i = 0; i < tryTimeSpans.length; ++i) {
       chrome.tabs.executeScript(null, {code: 'orderCar("' + orderDate_ + '", "' + tryTimeSpans[i] + '")'});
     }
   } else {
     chrome.tabs.executeScript(null, {code: 'orderCar("' + orderDate_ + '", "' + timeSpan_ + '")'});
   }
  });
  
  